package com.shelpe.services.tenant.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shelpe.services.tenant.mongomodel.ForbiddenCategory;
import com.shelpe.services.tenant.mongorepository.ForbiddenCategoryRepository;
import com.shelpe.services.tenant.service.ForbiddenCategoryService;

@Service
public class ForbiddenCategoryServiceImpl implements ForbiddenCategoryService{

	@Autowired
	private ForbiddenCategoryRepository categoryRep;
	
	@Override
	public void saveForbiddenCategory(ForbiddenCategory category) {
		// TODO Auto-generated method stub
		categoryRep.save(category);
	}

	@Override
	public void deleteForbiddenCategory(ForbiddenCategory category) {
		// TODO Auto-generated method stub
		categoryRep.delete(category);
	}

	@Override
	public ForbiddenCategory getForbiddenCategory(String category) {
		// TODO Auto-generated method stub
		return categoryRep.findOne(category);
	}

	@Override
	public List<ForbiddenCategory> getAllForbiddenCategories() {
		// TODO Auto-generated method stub
		Iterable<ForbiddenCategory> item = categoryRep.findAll();
		List<ForbiddenCategory> res = new ArrayList<ForbiddenCategory>();
		
		if(item != null){
			Iterator<ForbiddenCategory> it = item.iterator();
			while(it.hasNext()){
				res.add(it.next());
			}
		}
		
		return res;
	}

	@Override
	public Iterable<ForbiddenCategory> getAllForbiddenCategoriesIter() {
		// TODO Auto-generated method stub
		return categoryRep.findAll();
	}
	
}
